import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({

  state: {
    token: '',
    username: '用户',
    phone: '',
    isLogin: 0,
    isAdminLogin: 0
  },

  mutations: {
    isLogin (state, data) {
      state.isLogin = data
      sessionStorage.setItem('isLogin', data)
    },
    isAdminLogin (state, data) {
      state.isAdminLogin = data
      sessionStorage.setItem('isAdminLogin', data)
    },
    getToken (state, data) {
      state.token = data
      sessionStorage.setItem('token', data)
    },
    setUsername (state, data) {
      state.username = data
      sessionStorage.setItem('username', data)
    },
    setPhone (state, data) {
      state.phone = data
      sessionStorage.setItem('phone', data)
    },
    getUsername () {
      return sessionStorage.getItem('username')
    },
    getPhone () {
      return sessionStorage.getItem('phone')
    }
  }
})

export default store
